<template>
  <div>
    {{ count }}
    <button @click="destroy">点击卸载</button>
  </div>
</template>

<script>
export default {
  name: "Gege",
  data() {
    return {
      count: 1,
      busId: "",
    };
  },
  methods: {
    destroy() {
      this.$destroy();
    },
  },
  mounted() {
      //跟Pubsub类似,返回一个token,卸载时传入该token,可以卸载该事件的绑定
    this.busId = this.$bus.$on("count", (count) => {
      this.count = count;
    });
  },
  beforeDestroy() {
    this.$bus.$off("count",this.busId);
  },
};
</script>

<style>
</style>